package com.sjzs.web.dao;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.sjzs.web.po.Category;

public class CategoryDao extends HibernateDaoSupport {
	/**
	 * 保存分类方法 
	 * @param 
	 */
    public Category saveCategory(Category category  ){
    	String id=this.getSession().createSQLQuery("select SEQ_CATEGORY_ID.nextval from dual").uniqueResult().toString();
    	category.setCategoryid(Long.valueOf(id));
    	return (Category) this.getHibernateTemplate().save(category);
    }
    /**
     *  根据父ID查询 改类下的所有类别
     * @param parentId
     * @return
     */
    @SuppressWarnings("unchecked")
	public List<Category> searchCategoryByParentId(String parentId){
    	return this.getHibernateTemplate().find("from Category where 1=1 and PARENTID = ?",parentId);
    }
    /**
     *  根据分类ID 查询类别信息
     * @param categoryID
     * @return
     */
    public  Category searchCategoryByID(String categoryID){
    	return this.getHibernateTemplate().get(Category.class, categoryID);
    }
    /**
     * 查询所有分类
     * @return
     */
    @SuppressWarnings("unchecked")
	public List<Category> searchAllCategory(){
    	return this.getHibernateTemplate().find("from Category where 1=1 ");
    }
    
}
